<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title> 小程序管理系统</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="format-detection" content="telephone=no">

  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <style type="text/css">
    .layui-table{
      text-align: center;
    }
    .layui-table td, .layui-table th{
      text-align: center;
    }
  </style>
</head>
<body>
<div class="layui-layout layui-layout-admin">
  <div id = "divhead"></div>
  <div class="layui-body">
<form class="layui-form" action="" style = "margin-top: 30px;">
  <div class="layui-form-item">
    <label class="layui-form-label">标题</label>
    <div class="layui-input-block">
      <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input" value="{$res.title}">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">关于我们</label>
    <div class="layui-input-block">
      <textarea id="content" style="display: none;" name="content">{$res.content}</textarea>
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit="" lay-filter="*">立即提交</button>
      <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
    </div>
  </div>
  <input type="hidden" name="id" id = "id" value="{$res.id}"/>
</form>
  </div>
</div>

<script id="pic" type="text/html">
  {{#  layui.each(d.pics, function(index, item){ }}
    <img class="layui-upload-img" src="{{ item }}" style="width: 100px; height: 100px;">
  {{#  }); }}
</script>  
<script src="__PUBLIC__/layui/layui.js" charset="utf-8"></script>
<script src="__PUBLIC__/js/jquery-1.11.1.min.js" charset="utf-8"></script>

<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    $(function(){
        $('#divhead').load('/index.php/Tongcheng/Index/menu/wid/2.html');
    })
var pics = [{$vo.pics_arr}];
layui.use(['form','upload', 'layedit', 'laytpl'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,$ = layui.jquery
  ,upload = layui.upload
  ,layedit = layui.layedit
  ,laytpl = layui.laytpl;

  var getTpl = pic.innerHTML
  ,view = document.getElementById('view');

  layedit.set({
    uploadImage: {
      url: '{:U("Home/Public/upload1")}'
    }
  });
  var contIdx = layedit.build("content", {
    tool: ["strong","italic","underline","del","|","left","center","right","|","face","image"],height:400
  });
  

  var uploadInst = upload.render({
    elem: '#test1'
    ,url: '{:U("Home/Public/upload")}'
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){
        $('#demo1').attr('src', result).show(); //图片链接（base64）
      });
    }
    ,done: function(res){
      //如果上传失败
      if(res.err_code > 0){
        return layer.msg('上传失败');
      }else{
        // pics.push("https://www.58zltc.com/Uploads/"+res.file_name);
        laytpl(getTpl).render({pics:pics}, function(html){
          view.innerHTML = html;
        });
        $("#pics").val(pics.join(','));
      }
      //上传成功
    }
    ,error: function(){
      //演示失败状态，并实现重传
      var demoText = $('#demoText');
      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
      demoText.find('.demo-reload').on('click', function(){
        uploadInst.upload();
      });
    }
  });
  //监听提交
  form.on('submit(*)', function(data){
    var post_data = data.field;
    post_data.content = layedit.getContent(contIdx);
    $.post('{:U("AboutUsBack/edit")}', post_data, function(e) {
      layer.alert('保存成功',function(index){
        if(e == 1){
          parent.location.reload();
        }else{
          layer.close(index);
        }
      });
    });
    return false;
  });
  
  laytpl(getTpl).render({pics:pics}, function(html){
    view.innerHTML = html;
  });
});
</script>

</body>
</html>